﻿using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Collections;

namespace Exaction.ListSearch.WebParts.ListSearch
{
    [ToolboxItemAttribute(false)]
    public class ListSearch : WebPart
    {
        [Personalizable(), WebBrowsable(false), Category("Web Part Properties")]                
        public String SelectedWebPartId { get; set; }
        // Visual Studio might automatically update this path when you change the Visual Web Part project item.
        private const string _ascxPath = @"~/_CONTROLTEMPLATES/Exaction.ListSearch.WebParts/ListSearch/ListSearchUserControl.ascx";

        protected override void CreateChildControls()
        {
            ListSearchUserControl control = (ListSearchUserControl) Page.LoadControl(_ascxPath);
            control.SelectedWebPartId = SelectedWebPartId;
            control.ParentWebPartId = this.ID;
            Controls.Add(control);
        }
        ///<summary>
        /// Needed to add custom editor parts to page
        ///</summary>
        ///<returns>Editor part collection containing said parts</returns>
        public override EditorPartCollection CreateEditorParts()
        {
            ArrayList alControls = new ArrayList();
            alControls.Add(new ListSearchEditorPart()
            {
                ID = this.ID + "_EditorPart",
                Title = "Custom Properties",
                ChromeState = PartChromeState.Normal
            });
            EditorPartCollection epc = new EditorPartCollection(alControls);
            return epc;
        }

    }
}
